package br.ucb.musicbay.genero;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import br.ucb.musicbay.artista.Artista;

@Entity
@Table(name = "genero")
public class Genero implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String genero;	
	private Integer idgenero;	
	private List<Artista> artistas;
	
	@Id
	@GeneratedValue
	@Column(name = "id_genero")	
	public Integer getIdgenero() {
		return idgenero;
	}
	public void setIdgenero(Integer idgenero) {
		this.idgenero = idgenero;
	}
	
	@Column(name = "genero")
	public String getGenero() {
		return genero;
	}
	public void setGenero(String genero) {
		this.genero = genero;
	}
	
	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "genero_has_artista", joinColumns = { @JoinColumn(name = "id_genero") }, inverseJoinColumns = { @JoinColumn(name = "id_artista") })
	@OrderBy(value = "nome")
	public List<Artista> getArtistas() {
		return artistas;
	}
	public void setArtistas(List<Artista> artistas) {
		this.artistas = artistas;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((artistas == null) ? 0 : artistas.hashCode());
		result = prime * result + ((genero == null) ? 0 : genero.hashCode());
		result = prime * result
				+ ((idgenero == null) ? 0 : idgenero.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Genero other = (Genero) obj;
		if (artistas == null) {
			if (other.artistas != null)
				return false;
		} else if (!artistas.equals(other.artistas))
			return false;
		if (genero == null) {
			if (other.genero != null)
				return false;
		} else if (!genero.equals(other.genero))
			return false;
		if (idgenero == null) {
			if (other.idgenero != null)
				return false;
		} else if (!idgenero.equals(other.idgenero))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Genero [genero=" + genero + ", idgenero=" + idgenero + ", artistas=" + artistas + "]";
	}	
	
}
